package com.luck.dto;

import com.luck.config.dto.*;
import com.luck.feignClients.OrderServiceClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/user")
public class UserController {
    @Autowired
    private OrderServiceClient orderServiceClient;
    @GetMapping
    public List<Order> select(){
//        ThreadUtil.safeSleep(1000*20);
        OrderQuery 张三 = new OrderQuery().setUserName("张三");
        log.debug("--------------------{}",张三);
        return orderServiceClient.select(张三);
    }
    @PostMapping
    public String add(){
        OrderingProduct 手机 = new OrderingProduct().setId(1).setName("手机").setQty(1);
        OrderingDTO dto = new OrderingDTO().setUserName("张三").setProducts(Collections.singletonList(手机));
        OrderingOk ordering = orderServiceClient.ordering(dto);
        log.debug("{}",ordering);
        return "ok";
    }
}
